package com.stockz.equity.scanner.screen;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.stockz.equity.indicator.climaticVolume.BullishClimaticVolumeIndicator;
import com.stockz.equity.model.Bar;
import com.stockz.equity.scanner.screen.configuration.BullishClimaticVolumeScreenConfiguration;

@Component
public class BullishClimaticVolumeScreen implements MatchStrengthCalculatingScreen<BullishClimaticVolumeScreenConfiguration> {

	@Autowired
	private BullishClimaticVolumeIndicator bullishClimaticVolumeIndicator;
	
	private final BullishClimaticVolumeScreenConfiguration configuration = new BullishClimaticVolumeScreenConfiguration();
	private double matchStrength = 0;
	
	@Override
	public BullishClimaticVolumeScreenConfiguration getConfiguration() {
		return configuration;
	}
	
	
	@Override
	public double getMatchStrength() {
		return matchStrength;
	}
	
	@Override
	public int getMandatorySpan() {
		return bullishClimaticVolumeIndicator.getIndicatorConfiguration().getLongSpan()+configuration.getProbingSpan();
		//return bullishClimaticVolumeIndicator.getIndicatorConfiguration().getLongSpan();
	}

	@Override
	public boolean isMatch(List<Bar> barList) {
		bullishClimaticVolumeIndicator.getIndicatorConfiguration().setAverageTradePriceMultiple(configuration.getAverageTradePriceMultiple());
		bullishClimaticVolumeIndicator.getIndicatorConfiguration().setAverageTradeSizeMultiple(configuration.getAverageTradeSizeMultiple());
		bullishClimaticVolumeIndicator.getIndicatorConfiguration().setLongSpan(configuration.getLongSpan());
		bullishClimaticVolumeIndicator.getIndicatorConfiguration().setShortSpan(configuration.getShortSpan());
		bullishClimaticVolumeIndicator.getIndicatorConfiguration().setStochasticsUpperLimit(configuration.getStochasticsUpperLimit());
		bullishClimaticVolumeIndicator.getIndicatorConfiguration().setVolumeMultiple(configuration.getVolumeMultiple());
		
		/*matchStrength = bullishClimaticVolumeIndicator.getValue(barList);
		if(matchStrength >= configuration.getStrengthLowerLimit()){
			return true;
		}*/
	
		double[] values = bullishClimaticVolumeIndicator.getValues(barList);
		matchStrength = values[0];
		for(int i = 0; i < configuration.getProbingSpan(); i++){
			if(values[i] >= configuration.getStrengthLowerLimit()){
				matchStrength = values[i];
				return true;
			}
		}
		return false;
	}

}
